package com.example.consumer.controller;

import com.example.common.entity.Ad;
import com.example.common.entity.Message;
import com.example.consumer.service.AdService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
public class AdController {
    @Autowired
    AdService adService;

    /**
     添加广告
     */
    @ResponseBody
    @PostMapping("/user/addAd")
    public Message addAd(@RequestBody Ad ad){
//        log.info("***ad:" + ad);
        return adService.addAd(ad);
    }

    /**
     查询广告
     */
    @ResponseBody
    @PostMapping("/admin/findAd")
    public List<Ad> findAd(){
        return adService.findAd();
    }

    /**
     更新广告
     */
    @ResponseBody
    @PostMapping(value = "/admin/upAd")
    public Message upAd(@RequestBody Ad ad){
        return adService.upAd(ad);
    }

    /**
     用户查找正上架的广告
     */
    @ResponseBody
    @PostMapping("/user/findAding")
    public List<Ad> findAding(@RequestBody Ad ad){
        return  adService.findAding(ad);
    }

    /**
     删除广告
     */
    @ResponseBody
    @PostMapping("/admin/deleteAding")
    public Message deleteAding(@RequestBody Ad ad){
        adService.deleteAding(ad);
        return  new Message(800,"成功");
    }
}
